<style>
body {
    overflow-x: hidden;
    background-color: #f8f8f8;
}
p{margin:0;}
.page-head, .question-head {
    top: 0px;
    width: 100%;
    z-index: 1;
}
.question-head {
    font-size: 1.2em;
    padding: 0em;
    font-weight: bold;
    top: 0px;
}
.vote-div {
    color: #3a87ad;
    text-align: center;
    color: #009def;
    vertical-align: middle;
    cursor:pointer;
}
.voted {
    color: red;
    cursor: default;
}
.voteNum {
    font-size: 32px;
    font-weight: 100;
    clear: both;
    margin: 0px;
    line-height: 40px;white-space: pre;
}
.clickToVote {
	white-space: pre;
    font-size: 10px;
    margin: 0px;
    height: 100%;
}
#maincontent{background-color: transparent;margin-bottom: 20px;}
th,td{background-color: #fff;padding:5px 10px;}
.bs-navbar-collapse{display: none;}
</style>
<div class="row">
    	<div class="col-xs-12">
      		<div class="wx-cover-item noborder">
      			{{if $WxActivity['WxActivity']['coverimg']}}
	       			{{$this->Html->image($WxActivity['WxActivity']['coverimg'])}}
	       		{{/if}}
				<h2 class="question-head">{{$WxActivity['WxActivity']['name']}}</h2>
			</div>
			<p>查看次数: {{$WxActivity['WxActivity']['view_nums']}}</p>
       		<div style="border:2px dashed #CCC;padding:15px;margin:20px 0;">
				{{if $WxActivity['WxActivity']['started']}}
				<p>活动时间： {{substr($WxActivity['WxActivity']['started'],5,11)}} ~ {{substr($WxActivity['WxActivity']['ended'],5,11)}}</p>
				{{/if}}
				{{if $WxActivity['WxActivity']['summary']}}
				<p>{{nl2br($WxActivity['WxActivity']['summary'])}}</p>
				{{/if}}
			</div>
			
<style>
.vote-item {height:270px;text-align:center;min-width:140px;}
.vote-item img{max-height:160px;}
.vote-item-img {height:160px;display:table-cell;vertical-align: middle;text-align:center; width: 250px;max-width: 100%;}
.vote-item h4{height:32px;}
   
</style>			

			<div style="margin-top:10px;">		
			<div id="qa-list">
				<portlet cache="no" order="praise_nums desc" limit="200" portlet="body" model="Qa" list_tpl="inner" conditions="model=WxActivity&data_id=$id">
					<table id="qa-item-{{$item['id']}}" style="width:100%;box-shadow: 0 2px 5px #ddd;margin-bottom:10px;"><tbody>
					<tr>
								<td style="width:78%;">{{$item['name']}} </td>
								<td  style="width:22%;">
									<div class="vote-div" id="vote-{{$item['id']}}" data-id="{{$item['id']}}"> 
										<div class="voteNum ng-binding">{{$item['praise_nums']}}</div>
										<div class="clickToVote">点赞一下</div>
									</div>
								</td>
					</tr>
					</tbody></table>
				</portlet>		

				{{if $count<1}}
					<p>还没有任何人发表提议，赶紧抢占第一个吧</p>
				{{/if}}		
			</div>
			<br/>
			
		</div>
			
			{{if $WxActivity['WxActivity']['content']}}
		<div class="ui-portlet-header">
	      <span class="title">活动详情</span>            
		</div>
		<div>				
			<div class="wx-text-item noborder">{{$WxActivity['WxActivity']['content']}}</div>
		</div>
			{{/if}}


			<hr>
			<p class="text-center"><a href="/wx_activities/add?model=Qa" target="_blank">我也要发起提议活动</a></p>
			<p><br/></p>
</div>
</div>

{{if $WxActivity['WxActivity']['status'] == 1}}
<a class="btn btn-primary vote-btn navbar-fixed-bottom" >
	{{if $WxActivity['WxActivity']['button_name']}}{{$WxActivity['WxActivity']['button_name']}}{{else}}发表观点/意见{{/if}}
</a>
{{else}}
<a disabled="disabled" class="btn btn-default btn-lg navbar-fixed-bottom" >活动已结束</a>
{{/if}}

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">发表观点/意见</h4>
      </div>
      <div class="modal-body">
      	<div class="create-vote-div">
				<form name="voteForm" onsubmit="return submitVote(this);" method="post" action="/qas/add.json" class="form form-inline" id="voteForm">
					<textarea class="form-control no-shadow" id="vcontent" rows="6" cols="70" name="data[Qa][name]" placeholder="在这里输入你的提议..." required="required" style="margin-top: 32px;"></textarea>
					<div class="row" style="margin-top:8px">
						<div class="col-xs-6 col-md-6" style="padding-right:8px">
							<div  data-dismiss="modal" class="btn btn-default btn-block" id="goback">取消</div>	
						</div>
						<input type="hidden" name="data[Qa][data_id]" value="{{$id}}">
						<input type="hidden" name="data[Qa][model]" value="WxActivity">
						<input type="hidden" name="data[Qa][referer]" value="false">
						<div class="col-xs-6 col-md-6" style="padding-left:8px">
							<input type="submit" id="voteSubmit" class="btn btn-primary btn-block"  value="提交"/>
						</div>
					</div>
													 
				</form>
		</div>
      </div>
    </div>
  </div>
</div>
	
<script>

function submitVote(form){
	ajaxSubmitForm(form,function(request){
		if(request.ret ==0 ) {
			window.location = "/wx_activities/view/{{$id}}?newId="+request.data.Qa.id;
			//window.location.reload();
		}
	});
	return false;
}
function qvote(id){
	if($('#vote-'+id).hasClass('voted')) {
		return false;
	}
	var str_votedlist = $.cookie("qvotedList");
	var votedList;
	if(str_votedlist) {
		votedList = $.parseJSON(str_votedlist);				 
	}			 
	if(!votedList){
		votedList=[];
	}
	 
	if( jQuery.inArray(id,votedList) >=0 ){
		$('#vote-'+id).addClass('voted');
		$('#vote-'+id).find('.clickToVote').html('已点赞');
	}

	ajaxAction('/qas/praise/'+id,null,null,function(request){
		if(request.ret == 0) {
			$('#vote-'+id).find('.voteNum').each(function(){
				var nums = parseInt($(this).html()) ;
				$(this).html(++nums);
			});
			$('#vote-'+id).addClass('voted');
		}
		else if(request.ret == -1){
			$('#vote-'+id).addClass('voted');
		}

		votedList.push(id);
		$.cookie("qvotedList", JSON.stringify(votedList));
		$('#vote-'+id).find('.clickToVote').html('已点赞');
	});
}
$(function(){
	{{if $_REQUEST['newId']}}
		$('#qa-item-{{$_REQUEST['newId']}}').prependTo('#qa-list');
	{{/if}}

	$('.vote-div').click(function(){
		var id = $(this).data('id');
		qvote(id);
	});

	var str_votedlist = $.cookie("qvotedList");
	if(str_votedlist) {
		var votedList = $.parseJSON(str_votedlist);				 
		if(!votedList){
			votedList=[];
		}
		 
		for( var i in votedList) {
			$('#vote-'+votedList[i]).addClass('voted');
			$('#vote-'+votedList[i]).find('.clickToVote').html('已点赞');
		}
	}	

	$('.vote-btn').click(function(){
		$('#myModal').modal();		
		return false;
	})
})
</script>